package org.baojie.raft.message;

import org.baojie.raft.message.info.MessageInfo;
import org.baojie.raft.node.NodeName;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

public class LogRequest extends MessageInfo implements Serializable {

    private static final long serialVersionUID = -6951943559524330221L;

    // 选举的term
    private int term;

    // leader
    private NodeName leader;

    // 前一条日志的 term
    private int prevLogTerm = 0;

    // 前一条日志的索引
    private int prevLogIndex = 0;

    // leader 的 commitIndex
    private int leaderCommit = 0;

    // 复制的日志条目
    private List<Object> entries = Collections.emptyList();

    public LogRequest() {

    }

    @Override
    public Type type() {
        return Type.Unknown;
    }

    public int getTerm() {
        return term;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public NodeName getLeader() {
        return leader;
    }

    public void setLeader(NodeName leader) {
        this.leader = leader;
    }

    public int getPrevLogIndex() {
        return prevLogIndex;
    }

    public void setPrevLogIndex(int prevLogIndex) {
        this.prevLogIndex = prevLogIndex;
    }

    public int getPrevLogTerm() {
        return prevLogTerm;
    }

    public void setPrevLogTerm(int prevLogTerm) {
        this.prevLogTerm = prevLogTerm;
    }

    public List<Object> getEntries() {
        return entries;
    }

    public void setEntries(List<Object> entries) {
        this.entries = entries;
    }

    public int getLeaderCommit() {
        return leaderCommit;
    }

    public void setLeaderCommit(int leaderCommit) {
        this.leaderCommit = leaderCommit;
    }

    @Override
    public String toString() {
        return "LogRequest{" +
                ", term=" + term +
                ", leader=" + leader +
                ", entries=" + entries +
                ", prevLogTerm=" + prevLogTerm +
                ", prevLogIndex=" + prevLogIndex +
                ", leaderCommit=" + leaderCommit +
                '}';
    }

}
